home *** CD-ROM | disk | FTP | other *** search
- ;void indentln(strg,margin);
- ; char *strg;
- ; unsigned short margin;
-
- EXTRN _memory_model:byte
- EXTRN _error_code:byte
- EXTRN _time_out:byte
-
- _TEXT SEGMENT BYTE PUBLIC 'CODE'
- ASSUME CS:_TEXT
- PUBLIC _indentln
- _indentln proc near
- push bp ;
- mov bp,sp ;set stack frame
- push di ;
- push si ;
- cmp _memory_model,0 ;near or far?
- jle begin ;jump if near
- inc bp ;else add 2 to BP
- inc bp ;
- begin: push ds ;save DS
- mov ah,1 ;BIOS func to init prtr
- mov dx,0 ;choose LPT1
- int 17h ;initialize the prtr port
- mov di,[bp+6] ;margin value to DI
- sub ax,ax ;AX = 0
- mov es,ax ;ES = 0
- mov dx,es:[408H] ;get LPT1 base address
- sub bx,bx ;0 = no error
- mov _error_code,1 ;1 = printer error
- mov al,_time_out ;get _time_out seconds
- cmp _memory_model,2 ;data near or far?
- jb A1 ;jump if near
- lds si,dword ptr[bp+4] ;DS:SI pts to Strg
- inc bp ;add 2 to BP since dword ptr
- inc bp ;
- jmp short A2 ;
- A1: mov si,[bp+4] ;near case
- A2: or al,al ;don't allow zero seconds
- jnz A3 ;
- mov al,3 ;default to 3 seconds
- A3: mov cl,18 ;18 ticks per second
- mul cl ;
- mov [bp+6],ax ;save count
- sub cx,cx ;clear CX
- push si ;count string length...
- A4: cmp byte ptr [si],0 ;end of string?
- je A5 ;jump if so
- inc si ;forward string ptr
- inc cx ;inc length counter
- jmp short A4 ;loop
- A5: pop si ;restore ptr to start of string
- jcxz L4 ;CR/LF if null string
- or di,di ;test for 0-length margin
- jz L2 ;jump ahead if zero
- L1: mov al,32 ;set space char in AL
- call Writeit ;
- or ah,ah ;
- jz L6 ;
- dec di ;else dec margin counter
- jnz L1 ;
- L2: mov al,[si] ;mov character to AL
- inc si ;forward ptr for next time
- L3: call Writeit ;
- or ah,ah ;
- jz L6 ;
- loop L2 ;go write next char
- L4: inc cx ;will reenter loop
- cmp bh,2 ;BH = 0 first time around
- je L6 ;when 2, quit routine
- inc bh ;inc BH before looping
- cmp bh,2 ;second time?
- jne L5 ;jump ahead if not
- mov al,13 ;ready carriage return
- call Writeit ;
- or ah,ah ;
- jz L6 ;
- L5: mov al,10 ;ready line feed
- call Writeit ;
- or ah,ah ;
- jz L6 ;
- pop ds ;
- mov _error_code,0 ;0 = no error
- jmp short L7 ;
- L6: pop ds ;
- L7: pop si ;
- pop di ;
- pop bp ;
- cmp _memory_model,0 ;quit
- jle quit ;
- db 0CBh ;RET far
- quit: ret ;RET near
- Writeit PROC
- out dx,al ;send to output data register
- inc dx ;forward to status register
- push cx ;save string counter
- call GetBiosCount ;get timer reading
- mov bx,cx ;make copy
- add cx,[bp+6] ;add delay count
- cmp bx,cx ;if timer doesn't turn over...
- jb L8 ;go ahead
- mov cx,[bp+6] ;otherwise, extend delay
- L8: mov [bp+4],cx ;save target count on stack
- Wait: in al,dx ;get status value
- test al,8 ;test for printer error
- jz Error ;
- test al,80h ;test for Printer Ready
- jnz Ready ;jump if ready
- Error: call GetBiosCount ;
- cmp cx,[bp+4] ;compare to target
- jb Wait ;
- pop cx ;restore string counter
- mov ah,0 ;return code for failure
- jmp short L9 ;return
- Ready: pop cx ;restore string counter
- inc dx ; output control register
- mov al,13 ;bits for strobe signal
- out dx,al ;send the signal
- dec al ;change to strobe OFF
- out dx,al ;send the signal
- dec dx ;point back to
- dec dx ; base address
- mov ah,1 ;return code for success
- L9: ret ;
- Writeit endp
- GetBIOSCount PROC
- push dx ;return value in CX:DX
- push ax ;
- sub ah,ah ;function number
- int 1ah ;get timer count
- mov cx,dx ;low word in CX
- pop ax ;
- pop dx
- ret
- GetBIOSCount endp
- _indentln endp
- _TEXT ENDS
- END